package com.work.chat.custom.server.controller;

import com.work.chat.common.util.Response;
import com.work.chat.common.util.StaticProperties;
import com.work.chat.custom.server.config.model.BasePage;
import com.work.chat.custom.server.pojo.dto.InsertProductDTO;
import com.work.chat.custom.server.server.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RequestMapping(StaticProperties.PRODUCT)
@RestController
@Validated
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping(StaticProperties.QUERY_PRODUCT_LIST)
    public Response queryProductList(@RequestBody @Valid BasePage basePage)
    {
        return Response.buildSuccess(productService.queryProductPage(basePage));
    }

    @PostMapping(StaticProperties.INSERT_PRODUCT)
    public Response insertProduct(@RequestBody @Valid InsertProductDTO insertProductDTO)
    {
        productService.insertProduct(insertProductDTO);
        return Response.buildSuccess();
    }
}
